<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/23
 * Time: 下午11:54
 */

namespace App\Http\Repository;


use App\Http\Models\Goods;

class GoodsRepository implements Repository
{

    private $goods;

    public function __construct(Goods $goods)
    {
        $this->goods = $goods;

    }

    public function getGoodsById($id, array $columns = ['*'])
    {

        return $this->goods->find($id, $columns);
    }

    public function getGoodsList($where, $offset, $limit, $columns)
    {
        $query = $this->goods->with(['product' => function($query) use ($where) {

            foreach ($where as $item) {

                $query->where($item['key'], $item['operator'], $item['value']);

            }

        }]);

        return $query->offset($offset)->limit($limit)->get($columns);
    }

}